package app;

import gui.designComponents.TMTPanel;
import gui.mainGUIs.FooterPanel;
import gui.mainGUIs.HeaderPanel;
import gui.mainGUIs.NavigationControlPanel;
import gui.specialGUIs.EventSinglePanel;
import gui.specialGUIs.LoginPanel;
import gui.specialGUIs.MemberSinglePanel;
import gui.specialGUIs.OverviewPanel;
import gui.specialGUIs.ParticipantsPanel;
import gui.specialGUIs.StartView;
import gui.specialGUIs.StatsPanel;
import gui.specialGUIs.TrainingPlanPanel;

import java.awt.BorderLayout;

import definitions.Commands;

/**
 * View of this applications. Creates and manages every View of this
 * applications. The central controller sends this Class the information, which
 * content has to be shown.
 * 
 * @author MK
 * 
 */
public class View extends TMTPanel {

	private HeaderPanel header;
	private NavigationControlPanel navigation;
	private FooterPanel footer;
	private TMTPanel mainContent;
	private Model model;
	private Controller controller;
	private LoginPanel loginPanel;
	private StartView startView;
	private OverviewPanel modelOverviewPanel;
	private EventSinglePanel eventSinglePanel;
	private MemberSinglePanel memberSinglePanel;
	private StatsPanel statsPanel;
	private TrainingPlanPanel trainingPlanPanel;
	private MemberSinglePanel profilePanel;
	private ParticipantsPanel participantsPanel;
	private TMTPanel lastPanel;

	private View() {
		
	}

	public View(Model model, Controller centralController) {
		super();

		this.model = model;
		this.controller = centralController;

		setLayout(new BorderLayout());

		this.header = new HeaderPanel(this.model, this.controller);
		this.navigation = new NavigationControlPanel(this.controller);
		this.footer = new FooterPanel(this.model);

		loginPanel = new LoginPanel(this.model, this.controller);

		startView = new StartView(this.model, this.controller);

		modelOverviewPanel = new OverviewPanel(this.model, this.controller,
				Commands.SHOW_EVENT_OVERVIEW);
		eventSinglePanel = new EventSinglePanel(this.model, this.controller);

		memberSinglePanel = new MemberSinglePanel(this.model, this.controller);

		statsPanel = new StatsPanel(this.model, this.controller);

		trainingPlanPanel = new TrainingPlanPanel(this.model, this.controller);

		profilePanel = new MemberSinglePanel(this.model, this.controller);

		participantsPanel = new ParticipantsPanel(this.model, this.controller);

		this.mainContent = loginPanel;

		add(header, BorderLayout.NORTH);
		add(mainContent, BorderLayout.CENTER);
		add(footer, BorderLayout.SOUTH);
	}

	public void setMainContent(String whatIsShown) {

		TMTPanel tempPanel = mainContent;
		remove(mainContent);

		if (whatIsShown.equals(Commands.SHOW_EVENT_OVERVIEW)) {
			modelOverviewPanel.update(whatIsShown);
			mainContent = modelOverviewPanel;
		} else if (whatIsShown.equals(Commands.SHOW_EVENT_ADDRESS_CHANGE)) {
			eventSinglePanel.updateAddress();
		} else if (whatIsShown.equals(Commands.SHOW_EVENT_SINGLE)) {
			eventSinglePanel.update();
			mainContent = eventSinglePanel;
		} else if (whatIsShown.equals(Commands.SHOW_LOGIN)) {
			loginPanel.update();
			mainContent = loginPanel;
		} else if (whatIsShown.equals(Commands.SHOW_MEMBER_OVERVIEW)) {
			modelOverviewPanel.update(whatIsShown);
			mainContent = modelOverviewPanel;
		} else if (whatIsShown.equals(Commands.SHOW_MEMBER_SINGLE)) {
			memberSinglePanel.update();
			mainContent = memberSinglePanel;
		} else if (whatIsShown.equals(Commands.SHOW_PROFILE)) {
			profilePanel.update();
			mainContent = profilePanel;
		} else if (whatIsShown.equals(Commands.SHOW_PARTICIPANTS)) {
			participantsPanel.update();
			mainContent = participantsPanel;
		} else if (whatIsShown.equals(Commands.SHOW_START_VIEW)) {
			startView.update();
			mainContent = startView;
		} else if (whatIsShown.equals(Commands.SHOW_STATS_OVERVIEW)) {
			statsPanel.update();
			mainContent = statsPanel;
		} else if (whatIsShown.equals(Commands.SHOW_TRAININGPLAN_CREATE)) {
			trainingPlanPanel.update();
			mainContent = trainingPlanPanel;
		} else if (whatIsShown
				.equals(Commands.SHOW_TRAININGPLAN_CREATE_WITH_SELECTION)) {
			trainingPlanPanel.appendLines();
		} else if (whatIsShown.equals(Commands.GO_BACK)) {
			mainContent = lastPanel;
		}

		add(mainContent, BorderLayout.CENTER);
		
		footer.update();
		updateUI();
		lastPanel = tempPanel;
	}

	public void showGUIAfterLogIn() {
		setMainContent(Commands.SHOW_START_VIEW);
		add(navigation, BorderLayout.WEST);
	}

	public void showGUIAfterLogOut() {
		setMainContent(Commands.SHOW_LOGIN);
		remove(this.navigation);
	}

	public HeaderPanel getHeader() {
		return header;
	}

	public NavigationControlPanel getNavigation() {
		return navigation;
	}

	public FooterPanel getFooter() {
		return footer;
	}

	public TMTPanel getMainContent() {
		return mainContent;
	}

	public Model getModel() {
		return model;
	}

	public Controller getCentralController() {
		return controller;
	}

	public LoginPanel getLoginPanel() {
		return loginPanel;
	}

	public StartView getStartView() {
		return startView;
	}

	public EventSinglePanel getEventSinglePanel() {
		return eventSinglePanel;
	}

	public MemberSinglePanel getMemberSinglePanel() {
		return memberSinglePanel;
	}

	public OverviewPanel getModelOverviewPanel() {
		return modelOverviewPanel;
	}

	public StatsPanel getStatsSinglePanel() {
		return statsPanel;
	}

	public TrainingPlanPanel getTrainingPlanPanel() {
		return trainingPlanPanel;
	}
}